//
//  HKBaseModuleController.m
//  HKUtilities
//
//  Created by 胡锦涛 on 2018/10/30.
//  Copyright © 2018 胡锦涛. All rights reserved.
//

#import "HKLibBaseController.h"

#define IsUITest NSProcessInfo.processInfo.environment[@"isUITest"].boolValue

@interface HKLibBaseController ()

@end

@implementation HKLibBaseController

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

///Present
- (void)hk_presentTo:(UIViewController*)vc {
    [self presentViewController:vc animated:YES completion:nil];
}

///返回事件
- (void)hk_back {
    NSArray *viewcontrollers=self.navigationController.viewControllers;
    if (viewcontrollers.count>1) {
        if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {
            //push方式
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        //present方式
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

///Dismiss
- (void)hk_dismiss{
    [self dismissViewControllerAnimated:YES completion:nil];
}

///回到根视图
- (void)hk_dismissToRoot {
    NSArray *viewcontrollers=self.navigationController.viewControllers;
    if (viewcontrollers.count>1) {
        if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {
            //push方式
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        //present方式
        UIViewController *rootVC = self.presentingViewController;
        while (rootVC.presentingViewController) {
            rootVC = rootVC.presentingViewController;
        }
        [rootVC dismissViewControllerAnimated:YES completion:nil];
    }
}

- (BOOL)shouldCustomizeNavigationBarTransitionIfHideable {
    return YES;
}
- (void)setTitle:(NSString *)title {
    [super setTitle:title];
    if (IsUITest && self.isViewLoaded) {
        self.view.accessibilityLabel = [NSString stringWithFormat:@"viewController-%@", self.title];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if (IsUITest) {
        self.view.accessibilityLabel = [NSString stringWithFormat:@"viewController-%@", self.title];
    }
    //    //1.获取系统interactivePopGestureRecognizer对象的target对象
    //    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    //    //2.创建滑动手势，taregt设置interactivePopGestureRecognizer的target，所以当界面滑动的时候就会自动调用target的action方法。
    //    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] init];
    //    [pan addTarget:target action:NSSelectorFromString(@"handleNavigationTransition:")];
    //    pan.delegate = self;
    //    //3.添加到导航控制器的视图上
    //    [self.navigationController.view addGestureRecognizer:pan];
    //    //4.禁用系统的滑动手势
    //    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
//#pragma mark - 滑动开始触发
//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
//    //只有导航的根控制器不需要右滑的返回的功能。
//    if (self.navigationController.viewControllers.count <= 1) {
//        return NO;
//    }
//    return YES;
//}
@end
